package com.qinggeng.project.system.controller;

import java.util.List;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.api.security.utils.ApiUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qinggeng.project.system.domain.OrdersReturn;
import com.qinggeng.project.system.service.IOrdersReturnService;


/**
 * 退单Controller
 * 
 * @author ruoyi
 * @date 2020-09-11
 */
@RestController
@RequestMapping("/system/orderRefund")
public class OrdersReturnController extends BaseController
{
    @Autowired
    private IOrdersReturnService ordersReturnService;

    /**
     * 查询退单列表
     */
    @PreAuthorize("@ss.hasPermi('orders:refund:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrdersReturn ordersReturn)
    {
        startPage();
        List<OrdersReturn> list = ordersReturnService.selectOrdersReturnList(ordersReturn);
        return getDataTable(list);
    }

    /**
     * 导出退单列表
     */
    @PreAuthorize("@ss.hasPermi('orders:refund:export')")
    @Log(title = "退单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrdersReturn ordersReturn)
    {
        List<OrdersReturn> list = ordersReturnService.selectOrdersReturnList(ordersReturn);
        ExcelUtil<OrdersReturn> util = new ExcelUtil<OrdersReturn>(OrdersReturn.class);
        return util.exportExcel(list, "refund");
    }

    /**
     * 获取退单详细信息
     */
    @PreAuthorize("@ss.hasPermi('orders:refund:query')")
    @GetMapping(value = "/{ordersReturnId}")
    public AjaxResult getInfo(@PathVariable("ordersReturnId") Long ordersReturnId)
    {
        return AjaxResult.success(ordersReturnService.selectOrdersReturnById(ordersReturnId));
    }

    /**
     * 新增退单
     */
    @PreAuthorize("@ss.hasPermi('orders:refund:add')")
    @Log(title = "退单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrdersReturn ordersReturn)
    {
        return toAjax(ordersReturnService.insertOrdersReturn(ordersReturn, ApiUtils.getUserId()));
    }

    /**
     * 修改退单
     */
    @PreAuthorize("@ss.hasPermi('orders:refund:edit')")
    @Log(title = "退单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrdersReturn ordersReturn)
    {
        return toAjax(ordersReturnService.updateOrdersRetrun(ordersReturn));
    }

    /**
     * 删除退单
     */
    @PreAuthorize("@ss.hasPermi('orders:refund:remove')")
    @Log(title = "退单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ordersReturnIds}")
    public AjaxResult remove(@PathVariable Long[] ordersReturnIds)
    {
        return toAjax(ordersReturnService.deleteOrdersRetrunByIds(ordersReturnIds));
    }
}
